Completed
Push — master ( 3c25dc...ef1a08 )
by Callum
01:07
created

server-spec.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
cc 1
c 5
b 1
f 1
nc 1
dl 0
loc 52
rs 9.4929
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B server-spec.js ➔ ... ➔ ??? 0 24 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import chai, { expect } from 'chai'
2
import chaiHttp from 'chai-http'
3
import xmldoc from 'xmldoc'
4
import fs from 'fs'
5
import server from './server'
6
7
chai.use(chaiHttp)
8
9
// describe('Runtime arguments', () => {
10
//   it('should clean the output directory when called with --clean', (done) => {
11
//     process.argv = ['--clean']
12
//     chai.request(server)
13
//   })
14
// })
15
16
describe('/POST email', () => {
17
  const toAddress = '[email protected]'
18
  const ccAddress = '[email protected]'
19
  const bccAddress = '[email protected]'
20
  const replyToAddress = '[email protected]'
21
  const htmlEmail = '<p>HTML Email</p>'
22
  const textEmail = 'Text Email'
23
  const emailSubject = 'Email Subject 😊'
24
  const fromEmail = '[email protected]'
25
  it('should succeed if email has all params', (done) => {
26
    chai.request(server)
27
      .post('/')
28
      .send({
29
        Action: 'SendEmail',
30
        'Destination.ToAddresses.member.1': toAddress,
31
        'Message.Body.Html.Data': htmlEmail,
32
        'Message.Body.Text.Data': textEmail,
33
        'Message.Subject.Data': emailSubject,
34
        'Destination.CcAddresses.member.1': ccAddress,
35
        'Destination.BccAddresses.member.1': bccAddress,
36
        'ReplyToAddresses.member.1': replyToAddress,
37
        Source: fromEmail,
38
      })
39
      .end((err, res) => {
40
        expect(res).to.have.status(200)
41
        const response = new xmldoc.XmlDocument(res.text)
42
        const path = response.valueWithPath('SendEmailResult.MessageId')
43
        expect(fs.readFileSync(path, 'utf8')).to.eq(htmlEmail)
44
        expect(fs.readFileSync(path.replace('body.html', 'body.txt'), 'utf8')).to.eq(textEmail)
45
        expect(fs.readFileSync(path.replace('body.html', 'headers.txt'), 'utf8')).to.eq(`Subject: ${emailSubject}\nTo Address: ${toAddress}\nCc Address: ${ccAddress}\nBcc Address: ${bccAddress}\nReply To Address: ${replyToAddress}\nSource: ${fromEmail}`)
46
        done()
47
      })
48
  })
49
  it('should fail if one param is not sent', (done) => {
50
    chai.request(server)
51
      .post('/')
52
      .send({
53
        Action: 'SendEmail',
54
        'Message.Body.Html.Data': htmlEmail,
55
        'Message.Body.Text.Data': textEmail,
56
        'Message.Subject.Data': emailSubject,
57
        Source: fromEmail,
58
      })
59
      .end((err, res) => {
60
        expect(res).to.have.status(500)
61
        const response = new xmldoc.XmlDocument(res.text)
62
        expect(response.valueWithPath('Code')).to.eq('MessageRejected')
63
        expect(response.valueWithPath('Message')).to.eq('One or more required fields was not sent')
64
        done()
65
      })
66
  })
67
})